package com.turnengine.client.local.location.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import com.turnengine.client.local.location.enums.LocationSignup;
import com.turnengine.client.local.unit.bean.IUnitCount;
import com.turnengine.client.local.unit.bean.UnitCountSerializer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * The Generated Location Serializer.
 */
public class GeneratedLocationSerializer implements IGeneratedLocationSerializer {

	@Override
	public IGeneratedLocation readObject(IDataReader reader) throws IOException {

		// Read fields
		LocationSignup signup = reader.readEnum(LocationSignup.class, true);
		int signupFactionId = reader.readInt();
		List<IUnitCount> unitList = reader.readObjectCollection(new ArrayList<IUnitCount>(), true, false, new UnitCountSerializer());

		// Create object
		IGeneratedLocation object = new GeneratedLocation();
		object.setSignup(signup);
		object.setSignupFactionId(signupFactionId);
		object.setUnitList(unitList);
		return object;
	}

	public void writeObject(IDataWriter writer, IGeneratedLocation object) throws IOException {

		// Get fields
		LocationSignup signup = object.getSignup();
		int signupFactionId = object.getSignupFactionId();
		List<IUnitCount> unitList = object.getUnitList();

		// Write fields
		writer.writeEnum(signup, true);
		writer.writeInt(signupFactionId);
		writer.writeObjectCollection(unitList, true, false, new UnitCountSerializer());
	}
}
